﻿package exodecorateur_angryballs.maladroit.vues;

import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.util.Vector;

import angryballsDecorateur.modele.bases.BilleDecorable;
import angryballsDecorateur.visitor.BilleDessinateurVisitor;
import angryballsDecorateur.vue.RendereringThread;

/**
 * responsable du dessin des billes
 * 
 * ICI : IL N'Y A RIEN A CHANGER
 * 
 * 
 * */
public class Billard extends Canvas {

	private static final long serialVersionUID = 2999122523617546173L;

	Vector<BilleDecorable> billes;
	RendereringThread rendereringThread;
	BufferStrategy strategy;
	Graphics buffer;
	BilleDessinateurVisitor dessinateur;

	public Billard(Vector<BilleDecorable> billes) {
		this.billes = billes;
		rendereringThread = new RendereringThread(this);
		setIgnoreRepaint(true);
	}

	public void enableRendering() {
		createBufferStrategy(2);
		strategy = getBufferStrategy();
		buffer = strategy.getDrawGraphics();
		dessinateur = new BilleDessinateurVisitor(buffer);
		rendereringThread.start();
	}

	public void graphicalRender() {
		this.paint(buffer);
		for (int i = 0; i < billes.size(); i++)
			billes.get(i).accept(dessinateur);
		strategy.show();
	}

	public Vector<BilleDecorable> getBilles() {
		return this.billes;
	}
}
